Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Org.apache.bcel.generic.Instruction' - 3 code snippet(s) found

 Sample 1. Code Sample / Example / Snippet of org.apache.bcel.generic.InstructionHandle

    public void testRemoveLocalVariable() throws Exception {

final MethodGen mg = getMethod(Foo.class, "bar");



final LocalVariableGen lv = mg.getLocalVariables()[1];

assertEquals("variable name", "a", lv.getName());

final InstructionHandle start = lv.getStart();

final InstructionHandle end = lv.getEnd();

assertNotNull("scope start", start);

assertNotNull("scope end", end);

assertTrue("scope start not targeted by the local variable", Arrays.asList(start.getTargeters()).contains(lv));

assertTrue("scope end not targeted by the local variable", Arrays.asList(end.getTargeters()).contains(lv));



mg.removeLocalVariable(lv);



assertFalse("scope start still targeted by the removed variable", Arrays.asList(start.getTargeters()).contains(lv));

assertFalse("scope end still targeted by the removed variable", Arrays.asList(end.getTargeters()).contains(lv));

assertNull("scope start", lv.getStart());

assertNull("scope end", lv.getEnd());

}


   Like      Feedback      org.apache.bcel.generic.InstructionHandle


 Sample 2. Code Sample / Example / Snippet of org.apache.bcel.generic.InstructionList

    private void compare(final String name, final Method m) {

final Code c = m.getCode();

if (c == null) {

return; // e.g. abstract method

}

final byte[] src = c.getCode();

final InstructionList il = new InstructionList(src);

final byte[] out = il.getByteCode();

if (src.length == out.length) {

assertArrayEquals(name + ": " + m.toString(), src, out);

} else {

System.out.println(name + ": " + m.toString() + " " + src.length + " " + out.length);

System.out.println(bytesToHex(src));

System.out.println(bytesToHex(out));

for (final InstructionHandle ih : il) {

System.out.println(ih.toString(false));

}

fail("Array comparison failure");

}

}


   Like      Feedback      org.apache.bcel.generic.InstructionList


 Sample 3. Code Sample / Example / Snippet of org.apache.bcel.generic.Instruction

    public Instruction copy() {

Instruction i = null;

if (InstructionConst.getInstruction(this.getOpcode()) != null) {

i = this;

} else {

try {

i = (Instruction) clone();

} catch (final CloneNotSupportedException e) {

System.err.println(e);

}

}

return i;

}




   Like      Feedback      org.apache.bcel.generic.Instruction



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner